package leetcode.D700.T622;

/**
 * @File Info: leetcode -- <MyCircularQueue>
 * @Author: 18362
 * @Create: 2022-03-10 13:28:20 星期四
 */

class MyCircularQueue {

    private int[] arr;
    private int front=0,rear=-1,size=0;

    public MyCircularQueue(int k) {
        arr = new int[k];
    }

    public boolean enQueue(int value) {
        if (size==arr.length)
            return false;
        size++;
        rear = (rear+1) % arr.length;
        arr[rear] = value;
        return true;
    }

    public boolean deQueue() {
        if (size==0)
            return false;
        size--;
        front = (front+1) % arr.length;
        return true;
    }

    public int Front() {
        return size==0 ? -1 : arr[front];
    }

    public int Rear() {
        return size==0 ? -1 : arr[rear];
    }

    public boolean isEmpty() {
        return size==0;
    }

    public boolean isFull() {
        return size==arr.length;
    }
}